package com.baichang.taoshunda.controller.mobile.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.CarouselService;
import com.baichang.taoshunda.service.PaymentManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2018/5/8 0008.
 */
@Controller
@RequestMapping(ControllerConstants.REDCAROUSEL)
public class BusinessRedEnvelopesMController extends BaseMobileController {

    @Autowired
    private CarouselService carouselService;

    @Autowired
    private PaymentManagementService paymentManagementService;

    /**
     * 添加红包轮播图
     *
     * @param request
     * @param response
     */
    @RequestMapping("/addRedCarousel")
    public void addCarousel(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer busId = getInt(json, "busId", 0); //商家id
                return carouselService.addRedCarousel(busId);
            }
        });
    }

    /**
     * 查询全部的过往记录  1轮播图  2红包  3推荐商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryAllHistory")
    public void queryAllHistory(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) throws ServiceException {
                Integer busId = getInt(s, "busId", 0); //商家id
                Integer type = getInt(s, "type", 0);
                return carouselService.queryAllHistory(busId, type);
            }
        });
    }
}
